//权限文件
//白名单 
import router from './router'
import store from './store'

const whiteList = ['/reg','/login']

router.beforeEach((to,from,next)=>{
  // console.log(to,from,next);
  const token = store.state.token
  if(token){
    if(to.path==='/login'){
      next('/')
    }else{
      next()
    }
  }else{
    if (whiteList.includes(to.path)) {
      //判断路径是否存在白名单中 .includes 返回 true / flase
      next()
    }else{
      next('/login')
    }
  }
})